package com.tiancheng.trade.merchant.controller;

import com.alibaba.fastjson.JSON;
import com.tiancheng.commom.pay.gaocheng.notify.GcMerchantNotify;
import com.tiancheng.trade.commom.core.enums.PaymentChannelEnum;
import com.tiancheng.trade.merchant.dto.MerchantRegNotifyRes;
import com.tiancheng.trade.merchant.service.IMerchantPayRegService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/notify")
@Slf4j
public class NotifyController {

    @Resource
    private IMerchantPayRegService merchantPayRegService;

    /**
     * 银联商务支付通道——商户注册进件通知接收（支付渠道回调）
     * 银联商务支付通道——支付渠道商户进件消息通知
     *
     * @param paramsMap
     * @return
     */
    @RequestMapping(value = "/merchantRegNotify")
    public Object umsPayResult(@RequestParam Map<String, Object> paramsMap) {
        try {
            log.info("商户注册进件通知回调数据:{}", JSON.toJSONString(paramsMap));
            return merchantPayRegService.notifyHandler(paramsMap, PaymentChannelEnum.UMS);
        } catch (Exception e) {
            log.error("商户注册进件通知回调数据json error");
        }
        int resStatus = 0;
        return resStatus == 0 ? "SUCCESS" : "FAILED";
    }

    /**
     * 高诚支付渠道——商户注册进件通知接收（支付渠道回调）
     * 高诚支付渠道——商户进件消息通知
     *
     * @param params
     * @return
     */
    @RequestMapping(value = "/gcMerchantNotify")
    @ResponseBody
    public Map<String,Object> gcNongHangMerchantNotify(@RequestBody Map<String, Object> params) {
        Map<String,Object> result=new HashMap<>();
        try {
            log.info("高诚支付渠道——商户进件消息回调数据:{}", JSON.toJSONString(params));
            MerchantRegNotifyRes merchantRegNotifyRes = merchantPayRegService.notifyHandler(params, PaymentChannelEnum.gao_cheng_nong_hang);
            result.put("code",merchantRegNotifyRes.isSuccess()?"200":"500");
        } catch (Exception e) {
            log.error("高诚支付渠道——商户进件消息回调数据json error");
            result.put("code","500");
        }
        return result;
    }
}
